/**
 * 输入验证
 */
function validate(){ 
   var functionName = $("#mname").val();
   var micon = $("#micon").val();   
   if(isEmpty(functionName)){	  
	  $.messager.alert("系统提示","菜单名称不能为空或null！","warning");
	  $("#mname").focus();
	  return false;
   }   
   if(!isEmpty(micon)){
   	  var ext = getFileExt(micon);   	  
   	  var b = (ext==".gif" || ext==".jpg" || ext==".png" || ext==".jpeg" || ext==".bmp");
   	  if(isEmpty(ext) || !b){   	  	 
	     $.messager.alert("系统提示","资源图标格式有误，请输入图片！","warning");
   	  	 $("#micon").focus();
   	  	 return false;
   	  }   	  
   }
   return true;
}

function clearValue(){
   $("input[type=text]").val("");
   $("input[type=radio][value='1']").attr("checked","checked");
   $("#m_remark").text("");
   $("#job").remove();
}
//保存菜单后的回调方法
function callback(data){
   if(data=="SUCCESS"){   	   	  
   	  $.messager.confirm("系统提示","系统菜单添加成功，是否继续添加？",reloadParent);
   }else if(data=="FAIL"){   	  
   	  $.messager.alert("系统提示","菜单添加失败，请重试！","error");
   }else{
   	  $.messager.alert("系统提示","保存菜单时系统异常："+data,"error");	
   }
}
//刷新列表数据
function reloadParent(r) {	
	if(r){		
	    clearValue();
	}else{	   
	   parent.reloadTable({tableId:'menus'});
	   parent.$('#addWin').window('close');
	}
	parent.reloadTree({treeId:'tree'});
}
$("#menu_save_btn").click(function(){
  if(validate()){
     submitForm({
       formId:'saveForm',
       url:'menuContorller.do?method=addMenu',
       callback:callback
    });
  }	
});
var jobline_add = 0;
$("#addline").click(function(){ 
   jobline_add+=1;
   $("#jobline").val(jobline_add);
   var str = "";
   str+='<tr id="jobline'+jobline_add+'">';  
   str+='<td><input type="text" name="name'+jobline_add+'" id="name'+jobline_add+'" style="width: 120px;" class="input"/></td>';
   str+='<td><input type="text" name="code'+jobline_add+'" id="code'+jobline_add+'" style="width: 120px;" class="input"/></td>';
   str+='<td><input type="radio" name="state'+jobline_add+'" id="yes'+jobline_add+'" value="1" checked="checked"/>是&nbsp;&nbsp;<input type="radio" name="state'+jobline_add+'" id="no'+jobline_add+'" value="0"/>否</td>';
   str+='<td><input type="text" name="operseqnum'+jobline_add+'" id="operseqnum'+jobline_add+'" size="4" class="input"/></td>';
   str+='<td><input type="text" name="iconCls'+jobline_add+'" id="iconCls'+jobline_add+'" style="width: 100px;" class="input"/></td>';
   str+='<td><select name="opertype'+jobline_add+'" id="opertype'+jobline_add+'" class="select"><option value="FUNTREE">按钮</option><option value="BUSINE">业务</option></select></td>';   
//   str+='<td style="text-align:center;"><input class="button_sample" type="button" style="color:red;" value="删除" onclick="rmline('+jobline_add+');"/></td>';
   str+='<td style="text-align:center"><a href="javascript:void(0)" style="color:red;" class="easyui-linkbutton l-btn l-btn-small" iconcls="icon-remove" onclick="rmline('+jobline_add+');"><span class="l-btn-left l-btn-icon-left"><span class="l-btn-text">删除</span><span class="l-btn-icon icon-remove">&nbsp;</span></span></a></td>';
   str+='</tr>';    
   $("#job").append(str);   
});
function rmline(obj){
   $("#jobline"+obj).remove();
}
